<!DOCTYPE html>
<html>
<head>
    <#import "../common/common.macro.ftl" as netCommon>
    <title>${title!"艺术上海"}</title>
    <meta charset="utf-8" />
    <meta name="keywords" content="${keywords?if_exists}" />
    <meta name="description" content="${description?if_exists}" />
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />


    <link href="/static/css/bootstrap.mini.css" rel="stylesheet" />
    <link href="/static/css/style.css" rel="stylesheet" />
    <link href="/static/css/common/index.css" rel="stylesheet" />

    <link href="/static/css/footer/index.css" rel="stylesheet" />
    <link href="/static/css/font/font-awesome.min.css" rel="stylesheet" />
    <link href="/static/css/font/font-awesome.min.css" rel="stylesheet" />
    <link href="/static/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <style>
        .container-p{
            width: 1200px;
        }
        .padding-y{
            margin: 20px;
        }
        .form-group label{
            margin: 10px 0px;
        }
    </style>

</head>
<body>
<!-- header -->
<@netCommon.commonHeader "首页" menu i18n/>
<section class="section-pagetop bg" style="margin-top: 110px">
    <div class="container container-p">
        <h2 class="title-page">我的收货地址</h2>
    </div> <!-- container //  -->
</section>

<section class="section-content padding-y ">
    <div class="container container-p">

        <!-- =========================  COMPONENT MYORDER 1 ========================= -->
        <div class="row">
            <aside class="col-md-3">
                <!--   SIDEBAR   -->
                <ul class="list-group">
                    <a class="list-group-item " href="/user/order"> 我的订单 </a>
                    <a class="list-group-item active" href="/user/setting"> 个人设置 </a>
                    <a class="list-group-item " href="/user/address"> 我的收货地址 </a>
                    <a class="list-group-item" href="/user/history"> 足迹 </a>
                </ul>

            </aside>
            <main class="col-md-9">

                <article class="card">

                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title mb-4" style="margin-bottom: 20px">个人设置</h4>

                                <div class="form-row">
                                    <div class="col form-group">
                                        <label>姓名</label>
                                        <input type="text" class="form-control" id="nickName"  value="">
                                    </div> <!-- form-group end.// -->
                                    <div class="col form-group">
                                        <label>真实姓名</label>
                                        <input type="text" class="form-control" id="realName" value="">
                                    </div>
                                </div>

                                <div class="form-row">
                                    <div class="form-group ">
                                        <label>邮箱</label>
                                        <input type="text" class="form-control" id="email">
                                    </div> <!-- form-group end.// -->
                                    <div class="form-group">
                                        <label>电话</label>
                                        <input type="text" class="form-control" id="mobile">
                                    </div> <!-- form-group end.// -->
                                </div> <!-- form-row.// -->

                                <button class="btn btn-primary btn-block" id="btn-add">设置</button>

                        </div> <!-- card-body.// -->
                    </div>
                </article>
            </main>
        </div>
    </div>
</section>
<!-- footer -->


<!-- script -->
<@netCommon.commonScript />


<script>

    $(function () {
        var user = getUserInfo();
        $('#email').val(user.email);
        $('#mobile').val(user.mobile);
        $('#nickName').val(user.nickName);
        $('#realName').val(user.realName);

        //过滤非法字符
        		function stripscript(s){
        			var pattern = new RegExp("[`~!#$^&*()=|{}':;',\\[\\]<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？]")
        			var rs = "";
        			for (var i = 0; i < s.length; i++) {
        				rs = rs+s.substr(i, 1).replace(pattern, '');
        			}
        		return rs;
        		}

        $("#btn-add").click(function () {
            if($('#nickName').val() && $('#nickName').val()==''){
                alert('请设置昵称')
                return;
            }

            var params = {
                email:  stripscript($('#email').val()) ,
                mobile:  stripscript($('#mobile').val()),
                nickName: stripscript($('#nickName').val()),
                realName:   stripscript($('#realName').val())
            }

            $.ajax({
                type: "POST",
                url: baseUrl+"api/user-center/app/user/info/update",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                headers: {
                    'lbv': '1.0',
                    'tenant' : 'PTC',
                    'token':  getToken(),
                },
                data: JSON.stringify(params),
                success: function (res) {
                    debugger;
                    if(res && res.code && res.code=='0' && res.data){
                        alert('修改成功')
                        localStorage.setItem('userInfo',JSON.stringify(res.data));
                    }
                    else{
                        alert(res.msg);
                        if(res.code=='-3'){
                            relogin(window.location.href);
                        }
                        
                    }
                },
                error: function (res) {

                }
            });


        })
    })

</script>



</body>
</html>
